const cwd = process.cwd()
const path = require('path')
const { program } = require("commander")
let CONFIG = require('../config/dait.config')

try {
  const _config = require(path.join(cwd, program.config))
  CONFIG = Object.assign({}, CONFIG, _config)
} catch (error) {}

const themePath = path.join(cwd, './themes', CONFIG.theme)

if (!CONFIG.configureWebpack.entry) {
  CONFIG.configureWebpack.entry = path.join(themePath, './main.js')
}
CONFIG.configureWebpack.alias['@theme'] = themePath

global.DAIT_CONFIG = CONFIG
global.THEME_PATH = themePath


module.exports = (command) => {
  console.log('dait-service run', command)
  require(`./${command}`)
}